const image_rx = /(!\[[^\]]+]\([^)]+\))/i
const more_rx = /<!--+\s*more\s*--+>/i

export default function (source, maxLength=100) {
  source = source.trim().replace(image_rx, '')
  if (more_rx.test(source)) {
    let index = more_rx.exec(source).index
    return source.substring(0, index).trim();
  }
  let index = source.indexOf('\n\n')
  if (index === -1) {
    index = source.length
  }
  index = Math.min(index, maxLength)
  return source.substr(0, index)
}
